#ifndef SHP_SHP_H
#define SHP_SHP_H

#include <string_view>
#include <vector>
#include <cstdint>
#include <memory>
#include "common/UintSeq.h"

class Shp
{
public:
    struct ShpHeader
    {
        uint16_t empty = 0; // always 0
        uint16_t width = 0;
        uint16_t height = 0;
        uint16_t frameTotal = 0;
    };
    struct ShpFrame
    {
        uint16_t x = 0;
        uint16_t y = 0;
        uint16_t width = 0;
        uint16_t height = 0;
        /**
         * flags is a bitset32
         * 01 HasTransparency Frame treated as having a transparent color
         * 10 UsesRle enable WW_RLE_Zero compression
         * if HasTransparency is disabled, UsesRle will never be enable, so flags just have status { 0, 1, 3 }
         */
        uint32_t flags = 3;
        /**
         * frameColor is a uint8_t[4]
         * it show what color to show on rider
         * it is used by map resources and SHP-based terrain pieces such as bridges.
         */
        uint8_t frameColor[4]{};
        uint32_t reserved = 0; // always 0
        uint32_t dataOffset = 0;
        std::shared_ptr<Uint8Seq>data = nullptr;
    };

public:
    ShpHeader header{};
    std::vector<ShpFrame> frames;
    Shp() = default;
    explicit Shp(const ShpHeader& header_);
    static std::shared_ptr<Shp> Load(const std::string_view& path);
    void Write(const std::string_view& path);
};

#endif //SHP_SHP_H
